#include "TextUI.h"
#include "UserInterfaceException.h"

TextUI::TextUI(const std::string &title) : title(title)
{
    PrintHello();
}

void TextUI::MainLoop()
{
    while (true) {
        try {
            this->GetInstAndExecute();
        } catch (BlankInput err) {
            continue;
        } catch (EndOfInput err) {
            break;
        } catch (UnfoundInstruction err) {
            logger->Print(err.what());
            continue;
        }
    }
}

void TextUI::PrintHello()
{
    size_t titleLen = title.size();
    size_t totalLen = titleLen + 10 * 2 + 2;
    std::string shapeLine(totalLen, '#');
    std::string helloStr = shapeLine + "\n" +  std::string(10, '#') + " " + title + " " +
                           std::string(10, '#') + "\n" + shapeLine + "\n";
    helloStr += "\ntips: please input <help> to get instruction information\n\n";
    logger->Print(helloStr);
}